<template>
  <div>
    <div>
      <label for="orderNo">订单号：</label>
      <input id="orderNo" v-model="value" />
      <button @click="infoFn">查询</button>
    </div>
    <div>
      <OrderInfo :goodInfo="goodInfo" v-show="isShow">
        <template #desc="{ desc, type }">
          <strong v-if="type === 0">{{ desc }}</strong>
          <img v-else-if="type === 1" :src="desc" />
        </template>
      </OrderInfo>

      <LogisticsInfo
        :orderInfo="orderInfo"
        v-show="isShow"
        :userName="userName"
      >
        <template #header="{ logisticsStatus, logisticsCompany, logisticsNo }">
          <div class="logistics-status red" v-if="logisticsStatus === 0">
            未发货
          </div>
          <div
            class="logistics-status yellow"
            v-else-if="logisticsStatus === 1"
          >
            已发货
          </div>
          <div class="logistics-status green" v-else-if="logisticsStatus === 2">
            已签收
          </div>
          <div class="logistics-status blue" v-else-if="logisticsStatus === 3">
            未签收
          </div>
          <div class="logistics-company">{{ logisticsCompany }}</div>
          <div class="logistics-no">{{ logisticsNo }}</div>
        </template>
        <template #list="{ logisticsInfo }">
          <li
            v-for="(item, index) in logisticsInfo"
            :key="index"
            v-judge="orderInfo.role"
          >
            <div class="logistics-info-list-time">{{ item.time }}</div>
            <div class="logistics-info-list-content">{{ item.content }}</div>
          </li>
        </template>
      </LogisticsInfo>
    </div>
  </div>
</template>

<script>
import OrderInfo from '@/components/OrderInfo.vue'
import LogisticsInfo from '@/components/LogisticsInfo.vue'
export default {
  components: {
    OrderInfo,
    LogisticsInfo,
  },
  data() {
    return {
      orderInfo: {
        orderNo: this.currentOrderNo,
        role: 'admin', // 角色 ==> 用于判断是否有查看用户详情的权限
        logisticsStatus: 2, // 0 未发货 1 已发货 2 已签收 3 未签收
        logisticsCompany: '顺丰速运', // 快递公司的名称
        logisticsNo: 'SF123456789', // 快件运单号
        logisticsInfo: [
          {
            time: '2023-02-01 10:00:00', // 时间
            content: '快件已发货', // 快递状态
          },
          {
            time: '2023-02-02 09:00:00',
            content: '快件到达深圳中心',
          },
          {
            time: '2023-02-03 08:00:00',
            content: '快件派送中',
          },
          {
            time: '2023-02-04 16:00:00',
            content: '已签收',
          },
        ],
      },
      goodInfo: {
        // 商品信息
        goodNo: '12345678912312', // 商品id
        goodName: '三体', // 商品名称
        type: 0, // 0 代表的是文本 1代表的是 图片
        // desc 描述 ==> 可以是图片 也可以是其他的东西。数据可以随便改
        desc: '一本关于科技的好书',
      },
      isShow: false,
      value: '',
      userName: '',
    }
  },
  methods: {
    infoFn() {
      this.$nextTick(() => {
        setTimeout(() => {
          if (this.value !== '') {
            this.isShow = true
          }
        }, 500)
      })
    },
  },
  directives: {
    judge: {
      inserted(ele, { value }) {
        // console.log(value)
        ele.style.display = value === 'admin' ? 'block' : 'none'
        ele.style.display = 'none'
      },
      update(ele, binding) {
        console.log(ele)
        console.log(binding)
        ele.style.display = binding.value === 'admin' ? 'block' : 'none'
      },
    },
  },
}
</script>

<style></style>
